﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace BinaryTimesInterface
{
    public static class StatusMessageSender
    {
        static string statusMessagesPath;

        static StatusMessageSender()
        {
            statusMessagesPath = Path.Combine(Path.GetTempPath(), "BinaryTimesStatusMessages");
        }

        public static void AddStatusMessage(int id, string text, bool isCritical = false)
        {
            if (!Directory.Exists(statusMessagesPath))
                Directory.CreateDirectory(statusMessagesPath);

            using (StreamWriter sr = new StreamWriter(Path.Combine(statusMessagesPath, string.Format("{0}{1}", isCritical ? "!" : "", id))))
                sr.WriteLine(text);
        }

        public static void RemoveStatusMessage(int id)
        {
            string filePath = Path.Combine(statusMessagesPath, string.Format("{0}", id));
            string filePath_critical = Path.Combine(statusMessagesPath, string.Format("!{0}", id));

            if (File.Exists(filePath_critical))
                File.Delete(filePath_critical);
            else
                File.Delete(filePath);
        }
    }
}
